﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ChangePassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Session["Permission"] != null)
        {
            Permission permission = Session["Permission"] as Permission;
            if (permission != null)
            {

                UserBLL bll = new UserBLL();
                if (string.IsNullOrEmpty(txtOldPsw.Text))
                {
                    Response.Write("<script> alert( '请输入旧密码！ ');location= 'ChangePassWord.aspx'</script> ");
                    return;
                }
                if (string.IsNullOrEmpty(txtNewPsw.Text))
                {
                    Response.Write("<script> alert( '请输入新密码！ ');location= 'ChangePassWord.aspx'</script> ");
                    return;
                }
                if (string.IsNullOrEmpty(txtPswConfirm.Text))
                {
                    Response.Write("<script> alert( '请输入密码确认！ ');location= 'ChangePassWord.aspx'</script> ");
                    return;
                }
                if (txtNewPsw.Text != txtPswConfirm.Text)
                {
                    Response.Write("<script> alert( '两次新密码不一致！ ');location= 'ChangePassWord.aspx'</script> ");
                    return;
                }
                if (bll.ChangePassWord(permission.UserID, txtOldPsw.Text, txtNewPsw.Text))
                {
                    Response.Write("<script> alert( '更改成功！ ');location= 'ChangePassWord.aspx'</script> ");
                    return;

                }
                else
                {
                    Response.Write("<script> alert( '更改失败！ ');location= 'ChangePassWord.aspx'</script> ");
                    return;
                }
            }
        }

    }
}
